﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Medical_Store_Billing.Component;
using System.Windows.Forms;
using Medical_Store_Billing.Object_Class;

namespace Medical_Store_Billing.Data_Access_Layer
{
    class XuathangDAL
    {
        Dataservice m_xuathangdal = new Dataservice();

        public DataTable Kiemtrakho(String mahang)
        {
            SqlCommand cmd = new SqlCommand("select soluongcon from sanpham where mahang='" + mahang + "'");
            m_xuathangdal.Load(cmd);
            return m_xuathangdal;
        }

        public DataTable Demxuathang()
        {
            SqlCommand cmd = new SqlCommand("select count(*) from phieuxuathang");
            m_xuathangdal.Load(cmd);

            return m_xuathangdal;
        }

        public bool Themxuathang(Xuathangclass m_x)
        {
            SqlCommand cmd = new SqlCommand("Insert into phieuxuathang values(@mapx,@ngay,@makh,@ghichu,@manv,@madondat)");
            cmd.Parameters.Add("mapx", SqlDbType.VarChar).Value = m_x.mapx;
            cmd.Parameters.Add("ngay", SqlDbType.SmallDateTime).Value = m_x.ngay;
            cmd.Parameters.Add("makh", SqlDbType.VarChar).Value = m_x.makh;
            cmd.Parameters.Add("ghichu", SqlDbType.Text).Value = m_x.ghichu;
            cmd.Parameters.Add("manv", SqlDbType.VarChar).Value = m_x.manv;
            cmd.Parameters.Add("madondat", SqlDbType.VarChar).Value = m_x.madathang;

            if (m_xuathangdal.ExecuteNonQuery(cmd) > 0)
            {
               
                return true;
            }
            else return false;
        }
        public DataTable Laydsxuathang()
        {
            SqlCommand cmd = new SqlCommand("select * from phieuxuathang");
            m_xuathangdal.Load(cmd);

            return m_xuathangdal;
        }

        public bool Themchitietxuathang(chitietxuathangclass m_x)
        {
            SqlCommand cmd = new SqlCommand("Insert into chitietxuathang values(@mapx,@mahang,@soluong,@dongia)");
            cmd.Parameters.Add("mapx", SqlDbType.VarChar).Value = m_x.mapx;

            cmd.Parameters.Add("soluong", SqlDbType.Int).Value = m_x.soluong;
            cmd.Parameters.Add("mahang", SqlDbType.VarChar).Value = m_x.mahang;
            cmd.Parameters.Add("dongia", SqlDbType.Float).Value = m_x.dongia;


            if (m_xuathangdal.ExecuteNonQuery(cmd) > 0)
            {
                return true;
            }
            else return false;
        }
        public DataTable Timxuathang(string name)
        {
            SqlCommand cmd = new SqlCommand("Select * from phieuxuathang where mapx like N'%" + name + "%'");
            m_xuathangdal.Load(cmd);
            return m_xuathangdal;
        }

        public DataTable Laychitietxuat(string mapx)
        {
            SqlCommand cmd = new SqlCommand("Select * from phieuxuathang where mapx='"+mapx+"'");
            m_xuathangdal.Load(cmd);
            return m_xuathangdal;
        }
        public DataTable Laychitietxuat1(string mapx)
        {
            SqlCommand cmd = new SqlCommand("Select * from chitietxuathang where mapx='" + mapx + "'");
            m_xuathangdal.Load(cmd);
            return m_xuathangdal;
        }
    }
}
